window.onload = function () {
  //封装获取元素的函数
  function qs(ele) {
    return document.querySelector(ele)
  }
  //配置请求根路径
  axios.defaults.baseURL = 'http://124.223.14.236:3001/api'

  //获取表单数据，发起请求 
  qs('#form').addEventListener('submit', async function (e) {
    e.preventDefault()
    const { data: res } = await axios({
      method: 'POSt',
      url: '/user/reg',
      data: {
        username: qs('#username').value.trim(),
        password: qs('#password').value.trim(),
        phone: qs('#phone').value.trim(),
        question: qs('#question').value.trim(),
        answer: qs('#answer').value.trim(),
        sex: qs('[name=sex]').value * 1,
        vip: qs('[name=vip]').value * 1,
      }
    })
    console.log(res);
    if (!res.success) return alert(res.msg)
    this.reset()
    alert('注册成功')
    location.href = '../01-loginBaseCode/login.html'
  })
}